Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

trio.sleep_forever should be NoReturn #3096

Merged
merged 5 commits into from
Sep 30, 2024

Conversation

Redoubts
Copy link
Member

Fixes #3095

Copy link

codecov bot commented Sep 27, 2024

Codecov Report

All modified and coverable lines are covered by tests ✅

Project coverage is 99.58%. Comparing base (4e979bf) to head (e5f38f3).
Report is 1 commits behind head on main.

Additional details and impacted files
@@           Coverage Diff           @@
##             main    #3096   +/-   ##
=======================================
  Coverage   99.58%   99.58%           
=======================================
  Files         121      121           
  Lines       17992    18002   +10     
  Branches     3245     3248    +3     
=======================================
+ Hits        17917    17927   +10     
  Misses         52       52           
  Partials       23       23           
Files with missing lines Coverage Δ
src/trio/_tests/test_timeouts.py 98.56% <100.00%> (+0.09%) ⬆️
src/trio/_timeouts.py 100.00% <100.00%> (ø)

Copy link
Contributor

@A5rocks A5rocks left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It's a shame we have to use type ignores but this makes sense to me!

@A5rocks A5rocks added the typing Adding static types to trio's interface label Sep 27, 2024
@TeamSpen210
Copy link
Contributor

Well, actually mypy is correct. If someone did trio.lowlevel.reschedule(), sleep_forever() could succeed. That's totally incorrect to do of course. We could just add a raise TrioInternalError("Should never have been rescheduled!") after the await, which will quiet the type error and make sure you can't do that any more.

Copy link
Member

@CoolCat467 CoolCat467 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks great

@A5rocks A5rocks merged commit f508bb4 into python-trio:main Sep 30, 2024
38 checks passed
@trio-bot
Copy link

trio-bot bot commented Sep 30, 2024

Hey @Redoubts, it looks like that was the first time we merged one of your PRs! Thanks so much! 🎉 🎂

If you want to keep contributing, we'd love to have you. So, I just sent you an invitation to join the python-trio organization on Github! If you accept, then here's what will happen:

  • Github will automatically subscribe you to notifications on all our repositories. (But you can unsubscribe again if you don't want the spam.)

  • You'll be able to help us manage issues (add labels, close them, etc.)

  • You'll be able to review and merge other people's pull requests

  • You'll get a [member] badge next to your name when participating in the Trio repos, and you'll have the option of adding your name to our member's page and putting our icon on your Github profile (details)

If you want to read more, here's the relevant section in our contributing guide.

Alternatively, you're free to decline or ignore the invitation. You'll still be able to contribute as much or as little as you like, and I won't hassle you about joining again. But if you ever change your mind, just let us know and we'll send another invitation. We'd love to have you, but more importantly we want you to do whatever's best for you.

If you have any questions, well... I am just a humble Python script, so I probably can't help. But please do post a comment here, or in our chat, or on our forum, whatever's easiest, and someone will help you out!

@richardsheridan
Copy link
Contributor

This causes a regression for anyone who was using trio.sleep_forever combined with trio.lowlevel.reschedule. Okay, maybe they (we (I)) should have been using trio.lowlevel.wait_task_rescheduled but the RuntimeError should have been phased in with a warning over one release cycle.

@richardsheridan
Copy link
Contributor

The docstring for this function should also mention that it will raise RuntimeError if manually rescheduled.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
typing Adding static types to trio's interface
Projects
None yet
Development

Successfully merging this pull request may close these issues.

sleep_forever should be typed NoReturn
5 participants